﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Xpo;
using Aij1.Model;
using Aij1.BLL;
using DevExpress.Web.ASPxNavBar;

namespace Aij1.Cms
{
    public partial class LeftMenu : AdminPage
    {
        IList<P_MgrMenu> menus;
        protected void Page_Load(object sender, EventArgs e)
        {
            menus = MenuData.GetMenus(XpoSession);
            foreach (P_Menu menu in menus)
            {
                if (menu.ParentId == null)
                {
                    NavBarGroup group = new NavBarGroup(menu.Title, menu.Oid.ToString(), menu.ImageUrl);
                    ASPxNavBar1.Groups.Add(group);
                    AddMenuInGroup(group, menu);
                }
            }
        }

        void AddMenuInGroup(NavBarGroup group, P_Menu parentMenu)
        {
            foreach (var menu in menus.Where(m => m.ParentId == parentMenu))
            {
                NavBarItem item = new NavBarItem(menu.Title, menu.Oid.ToString(), menu.ImageUrl, menu.Url);
                item.Target = "workarea";
                group.Items.Add(item);
            }
        }
    }
}